package com.wondersgroup.framework.sample.listener;

import com.wondersgroup.framework.sample.component.grid.vo.GridVO;
import com.wondersgroup.framework.sample.component.grid.vo.GroupVO;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class InitGridDataListener
  implements ServletContextListener
{
  private static int SIZE = 145;

  public void contextInitialized(ServletContextEvent event)
  {
    initGridData(event.getServletContext());
    initGroupData(event.getServletContext());
  }

  private void initGridData(ServletContext context) {
    List gridData = new ArrayList();

    for (int i = 1; i <= SIZE; ++i) {
      GridVO vo = new GridVO();

      long t = System.currentTimeMillis();
      Random random = new Random(t + i);
      int currYear = 2010;
      int age = random.nextInt(60);
      int day = random.nextInt(28);
      int mon = random.nextInt(12);
      if (mon < 1)
        mon = 1;
      if (day < 1)
        day = 1;
      if (age < 1)
        age = 61;

      String sex = (random.nextBoolean()) ? "2" : "1";
      String image = (random.nextBoolean()) ? "images/yahoo.jpg" : "images/sina.jpg";

      vo.setId(String.valueOf(i));
      vo.setName("kiddy" + i);
      vo.setEmail("kiddy" + i + "@wondersgroup.com");
      vo.setAge(age);
      vo.setBirthday((currYear - age + 1) + "-" + ((mon < 10) ? "0" + mon : Integer.valueOf(mon)) + "-" + ((day < 10) ? "0" + day : Integer.valueOf(day)) + " 00:00:00");

      vo.setSex(sex);
      vo.setCreated("2010-04-09 14:38:10");
      vo.setDesc("about kiddy" + i + "...,[" + vo.toString() + "]");
      vo.setImage(image);

      gridData.add(vo);
    }

    context.setAttribute("gridList", gridData);
  }

  private void initGroupData(ServletContext context) {
    List groupData = new ArrayList();

    GroupVO groupVO1 = new GroupVO();
    groupVO1.setCompany("3m Co");
    groupVO1.setPrice(Double.valueOf(71.719999999999999D));
    groupVO1.setChange(Double.valueOf(0.02D));
    groupVO1.setPctChange(Double.valueOf(0.029999999999999999D));
    groupVO1.setIndustry("Manufacturing");
    groupData.add(groupVO1);

    GroupVO groupVO2 = new GroupVO();
    groupVO2.setCompany("Alcoa Inc");
    groupVO2.setPrice(Double.valueOf(29.010000000000002D));
    groupVO2.setChange(Double.valueOf(0.41999999999999998D));
    groupVO2.setPctChange(Double.valueOf(1.47D));
    groupVO2.setIndustry("Manufacturing");
    groupData.add(groupVO2);

    GroupVO groupVO3 = new GroupVO();
    groupVO3.setCompany("Altria Group Inc");
    groupVO3.setPrice(Double.valueOf(83.810000000000002D));
    groupVO3.setChange(Double.valueOf(0.28000000000000003D));
    groupVO3.setPctChange(Double.valueOf(0.34000000000000002D));
    groupVO3.setIndustry("Manufacturing");
    groupData.add(groupVO3);

    GroupVO groupVO4 = new GroupVO();
    groupVO4.setCompany("American Express Company");
    groupVO4.setPrice(Double.valueOf(52.549999999999997D));
    groupVO4.setChange(Double.valueOf(0.01D));
    groupVO4.setPctChange(Double.valueOf(0.02D));
    groupVO4.setIndustry("Finance");
    groupData.add(groupVO4);

    GroupVO groupVO5 = new GroupVO();
    groupVO5.setCompany("American International Group, Inc.");
    groupVO5.setPrice(Double.valueOf(64.129999999999995D));
    groupVO5.setChange(Double.valueOf(0.31D));
    groupVO5.setPctChange(Double.valueOf(0.48999999999999999D));
    groupVO5.setIndustry("Services");
    groupData.add(groupVO5);

    GroupVO groupVO6 = new GroupVO();
    groupVO6.setCompany("AT&T Inc.");
    groupVO6.setPrice(Double.valueOf(31.609999999999999D));
    groupVO6.setChange(Double.valueOf(-0.47999999999999998D));
    groupVO6.setPctChange(Double.valueOf(-1.54D));
    groupVO6.setIndustry("Services");
    groupData.add(groupVO6);

    GroupVO groupVO7 = new GroupVO();
    groupVO7.setCompany("Boeing Co.");
    groupVO7.setPrice(Double.valueOf(75.430000000000007D));
    groupVO7.setChange(Double.valueOf(0.53000000000000003D));
    groupVO7.setPctChange(Double.valueOf(0.70999999999999996D));
    groupVO7.setIndustry("Manufacturing");
    groupData.add(groupVO7);

    GroupVO groupVO8 = new GroupVO();
    groupVO8.setCompany("Caterpillar Inc.");
    groupVO8.setPrice(Double.valueOf(67.269999999999996D));
    groupVO8.setChange(Double.valueOf(0.92000000000000004D));
    groupVO8.setPctChange(Double.valueOf(1.3899999999999999D));
    groupVO8.setIndustry("Services");
    groupData.add(groupVO8);

    GroupVO groupVO9 = new GroupVO();
    groupVO9.setCompany("Citigroup, Inc.");
    groupVO9.setPrice(Double.valueOf(49.369999999999997D));
    groupVO9.setChange(Double.valueOf(0.02D));
    groupVO9.setPctChange(Double.valueOf(0.040000000000000001D));
    groupVO9.setIndustry("Finance");
    groupData.add(groupVO9);

    GroupVO groupVO10 = new GroupVO();
    groupVO10.setCompany("E.I. du Pont de Nemours and Company");
    groupVO10.setPrice(Double.valueOf(40.479999999999997D));
    groupVO10.setChange(Double.valueOf(0.51000000000000001D));
    groupVO10.setPctChange(Double.valueOf(1.28D));
    groupVO10.setIndustry("Manufacturing");
    groupData.add(groupVO10);

    GroupVO groupVO11 = new GroupVO();
    groupVO11.setCompany("Exxon Mobil Corp");
    groupVO11.setPrice(Double.valueOf(68.099999999999994D));
    groupVO11.setChange(Double.valueOf(-0.42999999999999999D));
    groupVO11.setPctChange(Double.valueOf(-0.64000000000000001D));
    groupVO11.setIndustry("Manufacturing");
    groupData.add(groupVO11);

    GroupVO groupVO12 = new GroupVO();
    groupVO12.setCompany("General Electric Company");
    groupVO12.setPrice(Double.valueOf(34.140000000000001D));
    groupVO12.setChange(Double.valueOf(-0.080000000000000002D));
    groupVO12.setPctChange(Double.valueOf(-0.23000000000000001D));
    groupVO12.setIndustry("Manufacturing");
    groupData.add(groupVO12);

    GroupVO groupVO13 = new GroupVO();
    groupVO13.setCompany("General Motors Corporation");
    groupVO13.setPrice(Double.valueOf(30.27D));
    groupVO13.setChange(Double.valueOf(1.0900000000000001D));
    groupVO13.setPctChange(Double.valueOf(3.7400000000000002D));
    groupVO13.setIndustry("Automotive");
    groupData.add(groupVO13);

    GroupVO groupVO14 = new GroupVO();
    groupVO14.setCompany("Hewlett-Packard Co.");
    groupVO14.setPrice(Double.valueOf(36.530000000000001D));
    groupVO14.setChange(Double.valueOf(-0.029999999999999999D));
    groupVO14.setPctChange(Double.valueOf(-0.080000000000000002D));
    groupVO14.setIndustry("Computer");
    groupData.add(groupVO14);

    GroupVO groupVO15 = new GroupVO();
    groupVO15.setCompany("Honeywell Intl Inc");
    groupVO15.setPrice(Double.valueOf(38.770000000000003D));
    groupVO15.setChange(Double.valueOf(0.050000000000000003D));
    groupVO15.setPctChange(Double.valueOf(0.13D));
    groupVO15.setIndustry("Manufacturing");
    groupData.add(groupVO15);

    GroupVO groupVO16 = new GroupVO();
    groupVO16.setCompany("Intel Corporation");
    groupVO16.setPrice(Double.valueOf(19.879999999999999D));
    groupVO16.setChange(Double.valueOf(0.31D));
    groupVO16.setPctChange(Double.valueOf(1.5800000000000001D));
    groupVO16.setIndustry("Computer");
    groupData.add(groupVO16);

    GroupVO groupVO17 = new GroupVO();
    groupVO17.setCompany("International Business Machines");
    groupVO17.setPrice(Double.valueOf(81.409999999999997D));
    groupVO17.setChange(Double.valueOf(0.44D));
    groupVO17.setPctChange(Double.valueOf(0.54000000000000004D));
    groupVO17.setIndustry("Computer");
    groupData.add(groupVO17);

    GroupVO groupVO18 = new GroupVO();
    groupVO18.setCompany("Johnson & Johnson");
    groupVO18.setPrice(Double.valueOf(64.719999999999999D));
    groupVO18.setChange(Double.valueOf(0.059999999999999998D));
    groupVO18.setPctChange(Double.valueOf(0.089999999999999997D));
    groupVO18.setIndustry("Medical");
    groupData.add(groupVO18);

    GroupVO groupVO19 = new GroupVO();
    groupVO19.setCompany("JP Morgan & Chase & Co");
    groupVO19.setPrice(Double.valueOf(45.729999999999997D));
    groupVO19.setChange(Double.valueOf(0.070000000000000007D));
    groupVO19.setPctChange(Double.valueOf(0.14999999999999999D));
    groupVO19.setIndustry("Finance");
    groupData.add(groupVO19);

    GroupVO groupVO20 = new GroupVO();
    groupVO20.setCompany("McDonald's Corporation");
    groupVO20.setPrice(Double.valueOf(36.759999999999998D));
    groupVO20.setChange(Double.valueOf(0.85999999999999999D));
    groupVO20.setPctChange(Double.valueOf(2.3999999999999999D));
    groupVO20.setIndustry("Food");
    groupData.add(groupVO20);

    GroupVO groupVO21 = new GroupVO();
    groupVO21.setCompany("Merck & Co., Inc.");
    groupVO21.setPrice(Double.valueOf(40.960000000000001D));
    groupVO21.setChange(Double.valueOf(0.40999999999999998D));
    groupVO21.setPctChange(Double.valueOf(1.01D));
    groupVO21.setIndustry("Medical");
    groupData.add(groupVO21);

    GroupVO groupVO22 = new GroupVO();
    groupVO22.setCompany("Microsoft Corporation");
    groupVO22.setPrice(Double.valueOf(25.84D));
    groupVO22.setChange(Double.valueOf(0.14000000000000001D));
    groupVO22.setPctChange(Double.valueOf(0.54000000000000004D));
    groupVO22.setIndustry("Computer");
    groupData.add(groupVO22);

    GroupVO groupVO23 = new GroupVO();
    groupVO23.setCompany("Pfizer Inc");
    groupVO23.setPrice(Double.valueOf(27.960000000000001D));
    groupVO23.setChange(Double.valueOf(0.40000000000000002D));
    groupVO23.setPctChange(Double.valueOf(1.45D));
    groupVO23.setIndustry("Services");
    groupData.add(groupVO23);

    GroupVO groupVO24 = new GroupVO();
    groupVO24.setCompany("The Coca-Cola Company");
    groupVO24.setPrice(Double.valueOf(45.07D));
    groupVO24.setChange(Double.valueOf(0.26000000000000001D));
    groupVO24.setPctChange(Double.valueOf(0.57999999999999996D));
    groupVO24.setIndustry("Food");
    groupData.add(groupVO24);

    GroupVO groupVO25 = new GroupVO();
    groupVO25.setCompany("The Home Depot, Inc.");
    groupVO25.setPrice(Double.valueOf(34.640000000000001D));
    groupVO25.setChange(Double.valueOf(0.34999999999999998D));
    groupVO25.setPctChange(Double.valueOf(1.02D));
    groupVO25.setIndustry("Retail");
    groupData.add(groupVO25);

    GroupVO groupVO26 = new GroupVO();
    groupVO26.setCompany("The Procter & Gamble Company");
    groupVO26.setPrice(Double.valueOf(61.909999999999997D));
    groupVO26.setChange(Double.valueOf(0.01D));
    groupVO26.setPctChange(Double.valueOf(0.02D));
    groupVO26.setIndustry("Manufacturing");
    groupData.add(groupVO26);

    GroupVO groupVO27 = new GroupVO();
    groupVO27.setCompany("United Technologies Corporation");
    groupVO27.setPrice(Double.valueOf(63.259999999999998D));
    groupVO27.setChange(Double.valueOf(0.55000000000000004D));
    groupVO27.setPctChange(Double.valueOf(0.88D));
    groupVO27.setIndustry("Computer");
    groupData.add(groupVO27);

    GroupVO groupVO28 = new GroupVO();
    groupVO28.setCompany("Verizon Communications");
    groupVO28.setPrice(Double.valueOf(35.57D));
    groupVO28.setChange(Double.valueOf(0.39000000000000001D));
    groupVO28.setPctChange(Double.valueOf(1.1100000000000001D));
    groupVO28.setIndustry("Services");
    groupData.add(groupVO28);

    GroupVO groupVO29 = new GroupVO();
    groupVO29.setCompany("Wal-Mart Stores, Inc.");
    groupVO29.setPrice(Double.valueOf(45.450000000000003D));
    groupVO29.setChange(Double.valueOf(0.72999999999999998D));
    groupVO29.setPctChange(Double.valueOf(1.6299999999999999D));
    groupVO29.setIndustry("Retail");
    groupData.add(groupVO29);

    GroupVO groupVO30 = new GroupVO();
    groupVO30.setCompany("Walt Disney Company (The) (Holding Company)");
    groupVO30.setPrice(Double.valueOf(29.890000000000001D));
    groupVO30.setChange(Double.valueOf(0.23999999999999999D));
    groupVO30.setPctChange(Double.valueOf(0.81000000000000005D));
    groupVO30.setIndustry("Services");
    groupData.add(groupVO30);

    context.setAttribute("groupList", groupData);
  }

  public void contextDestroyed(ServletContextEvent event)
  {
  }
}